<?php
/**
 * RbacPermissions
 * @文件名称: RbacPermissionsModel.php
 * @author: jawei
 * @Email: gaozhiwei@etcp.cn
 * @Date: 2017-06-06
 * @Copyright: 2017 悦畅科技有限公司. All rights reserved.
 * 注意：本内容仅限于悦畅科技有限公司内部传阅，禁止外泄以及用于其他的商业目的
 */
namespace app\models;
use app\components\DmpUtil;
use app\base\BaseException;
use app\base\BaseModel;
class RbacPermissionsModel extends BaseModel
{
    public static function tableName()
    {
        return 'dmp_rbac_permissions';
    }

    public static function getBatchByIds(array $ids)
    {
        if (!DmpUtil::issetEmptyCheckBool($ids)) {
            throw new BaseException('empty user id array in rbac perm model', 40323);
        }

        $idString = implode(',', $ids);
        $where = "id in ({$idString})";
        $rows = self::find()
            ->where($where)
            ->asArray()
            ->all();
        return $rows;
    }

    public static function getAll()
    {
        $rows = self::find()
            ->asArray()
            ->all();
        return $rows;
    }

    public static function addOne($data)
    {
        $model = new RbacPermissionsModel();
        $model->name = $data['name'];
        $model->routes = $data['routes'];
        $model->category = $data['category'];
        $model->description = $data['description'];
        $model->time_create = time();
        return $model->save();
    }
}
